
/**
 * 初始化登录框
 */
function initLoginDiv(){
	$(".login").click(function(){
		showLogin();
	});
	$(".login_btn,.qx_denglu").click(function(){
		$(".shade").css("display","none");
	});
	$('.chklist').hcheckbox();
	$('#chkitems').click(function(){
		if($('#chkitems').hasClass('checked')){
			  $('.chkitems').addClass('checked');
		}else{
			$('.chkitems').removeClass('checked');
		}
	});
}
/**
 * 显示登录窗口
 */
function showLogin(){
	$(".shade").css("display","block");
	$("html").css("overflow","hidden");
	$("body").css("overflow","hidden");
}

/**
 * 回车键执行登录
 */
function enterkey(){
	if(event.keyCode==13){
		f_login();
	}
}

/**
 * 登录方法
 * @return {TypeName} 
 */
function f_login(){		
	if(!checkform(document.forms[0])){	
		return false;
	}
	//saveCookieStatus();
	document.forms[0].submit();
}
/**
 * 重置
 */
function f_empty(){
	document.forms[0].loginName.value="";
	document.forms[0].userPass.value="";
}
function AddToFavorite(){
	//收藏本页地址
	var subUrl='<%="http://" + request.getServerName() + ":"+ request.getServerPort() + request.getContextPath()%>';
	window.external.AddFavorite(subUrl + "/index.jsp" ,'数字档案馆V2.0—馆藏资源管理系统'); 
}
function modifyPwd(){
	window.open('module/user/modifyPass.jsp','new','width=350,height=200,left=250,top=200,scrollbars=no');
}
/**
 * 验证
 * @param {Object} frm
 * @return {TypeName} 
 */
function checkform(frm){
	if (frm.loginName.value==""){
    	alert('请先输入用户名！');
    	frm.loginName.focus();
    	return false;
	}
	if (frm.userPass.value==""){
  		alert('请输入密码！');
  		frm.userPass.focus();
  		return false;
	}
	return true;
}
	
function f_enter(){
	if (event.keyCode==13){
		checkform(window.document.forms[0]);
	}
}

function setCookie(cookieInfo){//保存值到cookie中	
	var Days = 30;
	var exp = new Date(); 
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie='saveLoginName='+escape (cookieInfo.saveLoginName)+";path=/;expires=" + exp.toGMTString();
	document.cookie='loginNameCookie='+escape(cookieInfo.loginNameCookie)+";path=/;expires=" + exp.toGMTString();
	document.cookie='userPassCookie='+escape(cookieInfo.userPassCookie)+";path=/;expires=" + exp.toGMTString();
} 
function getCookieVal (offset) { //取得项名称为offset的cookie值  
    var endstr = document.cookie.indexOf (";", offset);    
    if (endstr == -1)  
        endstr = document.cookie.length;    
        return unescape(document.cookie.substring(offset, endstr));  
}
function getCookie(name){//根据名字取得cookie中的值
 	var arg = name + "=";    
    var alen = arg.length;    
    var clen = document.cookie.length;    
    var i = 0;    
    while (i < clen) {      
    var j = i + alen;      
    if (document.cookie.substring(i, j) == arg)        
             return (getCookieVal (j));      
            i = document.cookie.indexOf(" ", i) + 1;      
            if (i == 0) break;     
    }    
    return ;  
}
function getCookieStatus(){
	var saveLoginName=getCookie('saveLoginName');
	var loginNameCookie=getCookie('loginNameCookie');
	var userPassCookie=getCookie('userPassCookie');
	if(saveLoginName=="1"){
		$(".rem-pw").addClass("checked");
		$("#saveLoginName").attr("checked",true);
		document.getElementById("loginName").value=loginNameCookie;
		document.getElementById("userPass").value=userPassCookie;
	}else{
		$("#saveLoginName").attr("checked",false);
		$("#saveLoginName").removeAttr("checked");
	}
}
function saveCookieStatus(){
	var saveLoginName="0";
	var loginName=document.getElementById("loginName").value;	
	var userPass=document.getElementById("userPass").value;
	if(document.getElementById("saveLoginName").checked==true){
		saveLoginName="1";	
	}
	var cookieInfo={"saveLoginName":saveLoginName,"loginNameCookie":loginName,"userPassCookie":userPass};	
	setCookie(cookieInfo);
}	